const express = require("express");
const router = express.Router();
const JwtUtil = require("../../utils/jwt");

const attention = require("../../model/attention");
router.post("/getAttention", async (req, res) => {
    let token = req.headers["token"];
    let jwt = new JwtUtil(token);
    let result = jwt.verifyToken();
    if (result == "err") {
        // 提醒用户重新登录
        res.send({
            code: -1,
            msg: "登录已过期,请重新登录。",
        });
    } else {
        let { user_id, attention_name, create_time } = req.body;
        console.log(user_id, attention_name);
        await attention
            .getAttention(user_id, attention_name, create_time)
            .then((data) => {
                res.send(data);
            })
            .catch((error) => {
                res.send(error);
            });
    }
});
router.post("/selectAttention", async (req, res) => {
    let { user_id, attention_name } = req.body;
    console.log(user_id, attention_name);
    await attention
        .selectAttention(user_id, attention_name)
        .then((data) => {
            res.send(data);
        })
        .catch((error) => {
            res.send(error);
        });
});
router.post("/userAttention", async (req, res) => {
    let { user_id } = req.body;
    console.log(user_id);
    await attention
        .userAttention(user_id)
        .then((data) => {
            res.send(data);
        })
        .catch((error) => {
            res.send(error);
        });
});

// attentionManDetail
router.post("/attentionManDetail", async (req, res) => {
    let { source } = req.body;
    console.log(source);
    await attention
        .attentionManDetail(source)
        .then((data) => {
            res.send(data);
        })
        .catch((error) => {
            res.send(error);
        });
});
module.exports = router;
